package com.cdxy.dmr.repository;

import com.cdxy.dmr.dataObject.SceneDO;
import com.cdxy.dmr.mapper.SceneMapper;
import com.cdxy.model.dto.base.mybatis.BaseRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 景点表 服务实现类
 * </p>
 *
 * @author autoGenCode
 * @since 2020-03-05
 */
@Repository
public class SceneRepository extends BaseRepository<SceneMapper, SceneDO> {
    /**
     * 查询热门景点
     *
     * @param size
     * @return
     */
    public List<SceneDO> listOrderBySearchNumAndReviewNum(int size) {
        return this.baseMapper.selectList(this.queryWrapper()
                .orderByDesc(SceneDO::getSearchNum)
                .orderByDesc(SceneDO::getReviewNum)
                .last("LIMIT " + size));
    }

    /**
     * 查询热门景点
     *
     * @param size
     * @param city
     * @return
     */
    public List<SceneDO> listByCityOrderBySearchNumAndReviewNum(String city, int size) {
        return this.baseMapper.selectList(this.queryWrapper()
                .eq(SceneDO::getCity, city)
                .orderByDesc(SceneDO::getSearchNum)
                .orderByDesc(SceneDO::getReviewNum)
                .last("LIMIT " + size));
    }

    /**
     * 查询热门景点城市
     *
     * @param size
     * @return
     */
    public List<SceneDO> listGroupByCityOrderBySearchNumAndReviewNum(int size) {
        return this.baseMapper.selectList(this.queryWrapper()
                .orderByDesc(SceneDO::getSearchNum)
                .orderByDesc(SceneDO::getReviewNum)
                .groupBy(SceneDO::getCity)
                .last("LIMIT " + size));
    }

    /**
     * 查询景点
     *
     * @param city
     * @param size
     * @return
     */
    public List<SceneDO> listByCityOrderBySearchNu(String city, int size) {
        return this.baseMapper.selectList(this.queryWrapper()
                .eq(SceneDO::getCity, city)
                .orderByDesc(SceneDO::getSearchNum)
                .last("LIMIT " + size));
    }

    /**
     * 更新搜索次数
     *
     * @param id
     * @return
     */
    public boolean updateSearchNum(List<Integer> id) {
        return this.baseMapper.updateSearchNum(id);
    }

}
